<template>
	<view class="content" @click="close">
		<view class="store_box" @click="">
			<view class="store">
				<view class="left">
					<view class="title">{{ storeInfo.businessName }}</view>
					<view class="address time">{{ storeInfo.businessAddress.address }}</view>
					<view class="time">营业时间:{{ storeInfo.businessHours[0].businessStartTime }}~{{ storeInfo.businessHours[0].businessEndTime }}</view>
				</view>
				<view class="" style="height: 100%; display: flex; flex-direction: column; justify-content: space-between">
					<view class="right">
						<view class="right-box" style="margin-right: 12rpx" @click.stop="getPhone(storeInfo.businessMobile)">
							<u-icon name="phone-fill" :color="_temp_themeColor" size="20"></u-icon>
						</view>
						<view class="right-box" @click.stop="openMap(storeInfo.businessAddress.longitude, storeInfo.businessAddress.latitude)">
							<u-icon name="map-fill" :color="_temp_themeColor" size="20"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="paypal_box">
			<view class="menu_box box_shadow">
				<view class="head">
					<view class="left"><span>提货方式</span></view>
					<view class="right"></view>
				</view>
				<view class="delivery_box">
					<u-radio-group v-model="logisticsType" placement="row" @change="selectOrderTap()">
						<u-radio v-for="(item, index) in delivery" :key="index" :activeColor="_temp_themeColor" :name="item.id" :label="item.name" shape="square"></u-radio>
					</u-radio-group>
				</view>
			</view>
			
			<view class="menu_box box_shadow" v-if="logisticsType == 1">
				<address-select @address="address"></address-select>
			</view>
			
			<!-- 自提 -->
			<view v-if="logisticsType == 3" class="Selfpickup" style="width: 100%; background-color: #fff; box-sizing: border-box">
				<view class="menu_box box_shadow">
					<view class="head">
						<view class="left">
							<span>联系电话</span>
						</view>
						<view class="right"></view>
					</view>
					<view class="phone_box">
						<view class="input">
							<input type="number" maxlength="11" v-model="selfaddress.mobile" placeholder="请输入联系电话" />
						</view>
						<view class="btn">
							获取当前号码
							<button class="button" :disabled="userInfo.mobile != 0" open-type="getPhoneNumber" @getphonenumber="getBindWechatPhoneTap"></button>
						</view>
					</view>
				</view>
				<view class="pickUp" style="">
					<view class="title">自提点</view>
					<view class="">
						<view style="font-weight: bold;">{{ storeInfo.businessName }}</view>
						<view style="font-size: 24rpx; color: #aeb0b5">{{ selfaddress.address }}</view>
					</view>
				</view>
			</view>
			<view class="menu_box box_shadow">
				<view class="head">
					<view class="left"><span>商品信息</span></view>
					<view class="right">
						<!-- 共{{cardNumTotal}}件商品 -->
					</view>
				</view>
				<view class="goods_box">
					<view class="goods" v-for="(item, index) in shopCartList" :key="index">
						<view class="left">
							<view class="left">
								<image
									v-if=" Array.isArray(item.goodsSpecification) &&
									item.goodsSpecification.length > 0 &&
									item.goodsSpecification[0].specificationImages"
									:src="item.goodsSpecification[0].specificationImages"
									lazy-load="true"
									mode="aspectFill"
								></image>
								<image v-else-if="item.previewUrl" :src="item.previewUrl" lazy-load="true" mode="aspectFill">
								</image>
								<image v-else-if="item.plugsGoods" :src="item.plugsGoods.previewUrl" lazy-load="true"mode="aspectFill"></image>
							</view>
						</view>
						<view class="right">
							<view v-if="item.goodsName" class="title">{{ item.goodsName }}</view>
							<view v-else class="title">{{ item.plugsGoods.goodsName }}</view>
							<view class="goodsSpec" v-if="item.goodsSpecification.length > 0 && item.goodsSpecification[0] != null">
								<view v-for="(value, key) in JSON.parse(item.goodsSpecification[0].specificationName)" :key="key">{{ key + ':' + value }}</view>
							</view>
							<view class="price">
								<view class="">
									<view class="num" v-if="item.goodsSpecification.length > 0 && item.goodsSpecification[0] != null">
										{{ item.goodsSpecification[0].dealPrice }}
										<span v-if="scoreType==0">元</span>
										<span v-if="scoreType==1">积分</span>
									</view>
									<view class="num" v-else-if="item.goodsPrice">
										{{ item.goodsPrice }}
										<span v-if="scoreType==0">元</span>
										<span v-if="scoreType==1">积分</span>
									</view>
									<view class="num" v-else-if="item.plugsGoods">
										{{ item.plugsGoods.goodsPrice }}
										<span v-if="scoreType==0">元</span>
										<span v-if="scoreType==1">积分</span>
									</view>
								</view>

								<view class="buy">x{{ item.goodsNum }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 优惠券 -->
			<!-- <CouponSelect :couponList="couponList" :scoreType="scoreType"></CouponSelect> -->
			<coupon-select :couponList="couponList" :scoreType="scoreType"></coupon-select>
			
			<!-- 店铺优惠 -->
			<view class="menu_box firm_discount" v-if="firmDiscountMoney && firmDiscountMoney !== '0.00'">
				<text class="firm_discount_text">店铺折扣</text>
				<text>￥{{ firmDiscountMoney }}</text>
			</view>
			
			<view class="menu_box box_shadow">
				<view class="head">
					<view class="left"><span>支付信息</span></view>
					<view class="right"></view>
				</view>
				<view class="order_info_box">
					<view class="order_head">
						<view class="label">
							<view class="tit">商品合计</view>
							<view class="txt" v-if="scoreType==0">¥{{ goodsMoneyTotal }}</view>
							<view class="txt" v-if="scoreType==1">{{ goodsMoneyTotal }}积分</view>
						</view>
					</view>
					<view class="" v-if="logisticsType == 1">
						<view class="order_foot">
							<view class="label">
								<view class="tit">实际应付</view>
								<view class="txt" v-if="scoreType==0">¥{{ actualPay }}</view>
								<view class="txt" v-if="scoreType==1">{{ actualPay }}积分</view>
							</view>
						</view>
						<view class="order_foot">
							<view class="label">
								<view class="tit">配送费</view>
								<view class="txt">¥{{ distributionFee }}</view>
							</view>
						</view>
					</view>
					<view class="" v-if="logisticsType == 3">
						<view class="order_foot">
							<view class="label">
								<view class="tit">实际应付</view>
								<view class="txt" v-if="scoreType==0">¥{{ goodsMoneyTotal }}</view>
								<view class="txt" v-if="scoreType==1">{{ goodsMoneyTotal }}积分</view>
							</view>
						</view>
						<view class="order_foot">
							<view class="label">
								<view class="tit">配送费</view>
								<view class="txt">¥{{ distributionFee }}</view>
							</view>
						</view>
					</view>

					<view class="order_foot">
						<view class="label">
							<view class="tit">订单备注</view>
							<input type="text" v-model="ordermark" style="width: 76%; text-align: right; font-weight: 400" placeholder="订单备注" />
						</view>
					</view>
					<view class="order_foot">
						<view class="label">
							<view class="tit">优惠金额</view>
							<view class="">
								<view class="txt">¥{{ tootalDiscountMoney}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- <paypalType :paypalShow="paypalShow" :money="userData.moneys" :countDownTime="orderData.count_down_time" @close="paypalShow=false" @paypal="getPaypalOrder"></paypalType> -->
		<u-popup :show="paypalShow" mode="bottom" :round="10" @close="close()">
			<view class="showBox">
				<view class="pheader">请选择支付方式</view>
				<view class="paypalList">
					<view class="paypal" v-if="scoreType==0" @click="getPaypalOrder()">
						<view class="paypal-left">
							<view class="left">
								<aicon type="weixin1" size="30" color="#00c250"></aicon>
							</view>
							<view class="right">
								<view class="title">微信支付</view>
								<view class="info">简单快捷，推荐使用</view>
							</view>
						</view>
						<view class="icon">
							<aicon type="unfold-copy" size="18" color="#e2e2e2"></aicon>
						</view>
					</view>
					<!-- 余额支付-->
					<view style="margin: 20rpx auto" class="paypal" v-if="scoreType==0" @click.stop="balancePay()">
						<view class="paypal-left">
							<view class="left">
								<aicon type="moneybagfill" size="30" color="#ff2a36"></aicon>
							</view>
							<view class="right">
								<view class="title">余额支付</view>
								<view class="">
									<view class="info">可用余额：¥{{ userInfo.balance }}</view>
								</view>
							</view>
						</view>
						<view class="icon">
							<aicon type="unfold-copy" size="18" color="#e2e2e2"></aicon>
						</view>
					</view>
					<!-- 积分支付 -->
					<view class="paypal" v-if="scoreType==1" @click="scorePay()">
						<view class="paypal-left">
							<view class="left">
								<u-icon name="photo" color="#2979ff" size="28"></u-icon>
							</view>
							<view class="right">
								<view class="title">积分支付</view>
								<view class="info">可用积分：{{userInfo.integral}}</view>
							</view>
						</view>
						<view class="icon"> 
							<aicon type="unfold-copy" size="18" color="#e2e2e2"></aicon>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<view class="seat_box">
			<view class="seat"></view>
		</view>
		<view class="footer box_shadow">
			<view class="label">
				<view class="button" :style="{backgroundColor: _temp_themeColor}" @click="paypalOrderTap('form')">
					<span>确认下单并支付</span>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import {
	searchUserInfoById,
	getBusinessInfoById,
	searchPlugsCouponsByUserId,
	getShippingFeeEstimate,
	partnerAppletsWechatOrderPay,
	balanceOrderPay,
	getWeChartUserPhone,
	createOrder,
	integralOrderPay,
	updateUserInfo
} from "@/tools/request/api.js"
import md5 from '@/tools/utils/md5.js';
import JSONBig from 'json-bigint';
// import CouponSelect from './components/coupon-select.vue'
import { mapState, mapMutations, mapGetters, mapActions } from 'vuex'
import { makeContrast, makeLightColor } from '@/tools/utils/colorful.js'


export default {
	// components: {
	// 	CouponSelect
	// },
	data() {
		return {
			shopCartList: uni.getStorageSync('__ddminiShopCart'),
			num: 0,
			goodsTotal: 0,
			orderTotalMoney: 0, // 商品优惠前的总价
			cardNumTotal: 0,
			couponsIndex: -1,
			couponsList: [],
			addressData: '',
			addressIndex: '', // 地址下标
			orderInfo: '',
			goodsOrderList: [],
			// deliveryType: 1,
			userPhoneNumber: '',
			orderType: '',
			pintuanId: '',
			addCartInfo: [],
			list: [],
			payList: '',
			logisticsType: 1,
			goodsScoreStatus: false,
			paypalShow: false,
			time: '',
			userData: '',
			// deliveryType: 1,
			delivery: [
				{
					name: '配送',
					id: 1
				},
				{
					name: '自提',
					id: 3
				}
			],
			show2: false,
			cartListId: [], // 购物车ID列表
			couponList: [],
			useCouponId: '', // 使用优惠券ID
			balanceMoney: 0, // 余额
			scoreType: '',
			integral: 0,
			appointMoney: 0,
			ordermark: '',
			distributionFee: 0,
			addressInfo: {},
			pickupTime: '',
			pickupTime: '',
			selfaddress: {
				default: true,
				address: '',
				province: '',
				city: '',
				district: '',
				latitude: 0,
				name: '自提',
				mobile: '',
				longitude: 0,
				order: 0
			},
			Timelist: [],
		};
	},
	computed: {
		...mapState('pay_store',['original_goods_price', 'final_goods_price', 'selectCoupon', 'firm_rate']),
		...mapGetters('pay_store',['tootalDiscountMoney', 'firmDiscountMoney']),
		...mapState('app_store', ['currentAddress']),
		lightColor () {
			let light_color = makeLightColor(this._temp_themeColor, 0.6);
			console.log(light_color, 'light_colorlight_color')
			return light_color;
		},
		lightColor1 () {
			let light_color = makeLightColor(this._temp_themeColor, 0.9);
			console.log(light_color, 'light_colorlight_color___22')
			return light_color;
		},
		
		// 商品合计
		goodsMoneyTotal () {
			if (!this.final_goods_price) return;
			return Number(this.final_goods_price).toFixed(2);
		},
		// 实际应付
		actualPay () {
			if (!this.final_goods_price) return; 
			return (Number(this.final_goods_price) + Number(this.distributionFee)).toFixed(2);
		}
	},
	onShow() {
		
	},
	watch: {
		userInfo () {
			if (this.userInfo.mobile && this.userInfo.mobile.length == 11) {
				this.selfaddress.mobile = this.userInfo.mobile;
			}
		}
	},
	onLoad(e) {
		let self = this;
		self.getstoreInfo();
		this.getUserInfo();
		// this.addressData = this.addressList[0];
		let cart = self.shopCartList;
		let nums = 0;
		let mony = 0;
		let mony2 = 0;
		let goods = [];
		if (e.score) {
			self.scoreType = e.score;
		}
		if (e.pintuanId) {
			self.pintuanId = e.pintuanId;
		}
		let goods3 = [];
		cart.forEach((itm) => {
			nums += itm.goodsNum;
			let goods2 = [];
			let goods4 = [];
			if (itm.id != null) {
				goods3.push(itm.id);
			}
			if ((itm.goodsSpecification.length > 0) & (itm.goodsSpecification[0] != null)) {
				mony += itm.goodsSpecification[0].dealPrice * itm.goodsNum;
				itm.goodsSpecification.forEach((itm2) => {
					goods2.push(itm2.id);
					goods4.push(itm2.specificationName);
					if (itm.ctype === 'score') {
						self.goodsScoreStatus = true;
					}
				});
			} else {
				if (itm.plugsGoods) {
					mony2 += itm.plugsGoods.goodsPrice * itm.goodsNum;
				} else if (itm.goodsPrice) {
					mony2 += itm.goodsPrice * itm.goodsNum;
				}
			}
			goods.push({
				goodsId: itm.goodsId,
				goodsNum: itm.goodsNum,
				goodsName: !itm.plugsGoods ? itm.goodsName : itm.plugsGoods.goodsName,
				goodsSpecificationIds: goods2.toString() == '' ? 0 : goods2.toString(),
				goodsSpecificationNames: goods4.toString() == '' ? 0 : goods4.toString()
			});
		});
		let mony3 = mony + mony2;
		self.cardNumTotal = nums;
		self.goodsTotal = self.orderTotalMoney = mony3.toFixed(2);
		self.goodsOrderList = goods;
		self.cartListId = goods3;
		
		
		let originMoney = Number(self.goodsTotal);
		this.SET_ORIGINAL_GOODS_PRICE(originMoney);
		if (this.currentFirm.exJson && this.currentFirm.exJson.discountRate) { // 设置店铺优惠
			let rate = Number(this.currentFirm.exJson.discountRate);
			this.SET_FIRM_DISCOUNT(rate);
		}
		self.getcouponList();
	},
	methods: {
		...mapMutations('pay_store', ['SET_ORIGINAL_GOODS_PRICE', 'SET_FIRM_DISCOUNT']),
		getNowTime() {
			let date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();
			let hour = date.getHours();
			let minute = date.getMinutes();
			let second = date.getSeconds();
			let time = year + '-' + this.addZero(month) + '-' + this.addZero(day) + ' ' + this.addZero(hour) + ':' + this.addZero(minute) + ':' + this.addZero(second);
			return time;
		},
		addZero(s) {
			return s < 10 ? '0' + s : s;
		},
		getPhone(phone) {
			uni.makePhoneCall({
				phoneNumber: phone //仅为示例
			});
		},
		openMap(lon, lat) {
			uni.openLocation({
				latitude: parseFloat(lat),
				longitude: parseFloat(lon),
				scale: 18
			});
		},
		// 获取address-select组件的地址
		address (value) {
			this.addressData = value;
		},
		selectOrderTap(e) {
			this.logisticsType = e;
		},
		changeLog(e) {
			this.pickupTime = e;
		},
		// useCoupon(id) {
		// 	let self = this;
		// 	let ids = id;
		// 	let list = self.couponList;
		// 	self.show2 = false;
		// 	self.useCouponId = id;
		// 	let selCoupon = list.filter((item) => item.couponId == ids);
		// 	self.selectCoupon = selCoupon[0];
		// 	let goodstype = self.selectCoupon.plugsCoupons.goodsType;
		// 	if (goodstype == 1) {
		// 		if (selCoupon[0].couponType == 0 || selCoupon[0].couponType == 2 || selCoupon[0].couponType == 1) {
		// 			// let num = self.orderTotalMoney - selCoupon[0].plugsCoupons.couponDenomination;
		// 			let num = self.goodsTotal - selCoupon[0].plugsCoupons.couponDenomination;
		// 			self.goodsTotal = num.toFixed(2);
		// 		} else if (selCoupon[0].couponType == 3) {
		// 			// let num2 = self.orderTotalMoney * selCoupon[0].plugsCoupons.couponDenomination;
		// 			let num2 = self.goodsTotal * selCoupon[0].plugsCoupons.couponDenomination;
		// 			self.goodsTotal = num2.toFixed(2);
		// 		}
		// 	} else {
		// 		if (selCoupon[0].couponType == 0) {
		// 			// let money1 = self.orderTotalMoney - self.appointMoney;
		// 			let money1 = self.goodsTotal - self.appointMoney;
		// 			let money2 = self.appointMoney - selCoupon[0].plugsCoupons.couponDenomination;
		// 			self.goodsTotal = money1 + money2;
		// 		} else if (selCoupon[0].couponType == 3) {
		// 			// let money1 = self.orderTotalMoney - self.appointMoney;
		// 			let money1 = self.goodsTotal - self.appointMoney;
		// 			let money2 = self.appointMoney * selCoupon[0].plugsCoupons.couponDenomination;
		// 			let money3 = money1 + money2;
		// 			self.goodsTotal = money3.toFixed(2);
		// 		}
		// 	}
		// },
		getstoreInfo() {
			let storeInfo = this.storeInfo;
			const {address, city, district, latitude, longitude, province} = storeInfo.businessAddress;
			this.selfaddress.address = address;
			this.selfaddress.city = city;
			this.selfaddress.district = district;
			this.selfaddress.latitude = latitude;
			this.selfaddress.longitude = longitude;
			this.selfaddress.province = province;
			
			let cart = this.shopCartList;
			let expressMoney = 0;
			if (storeInfo.shopExpressFee.allShopExpressFeeAccumulateORNot) {
				if (storeInfo.shopExpressFee.allShopExpressFeeAccumulateORNot == 1) {
					cart.forEach((itm) => {
						expressMoney += itm.distributionFee;
					});
				} else {
					expressMoney = storeInfo.shopExpressFee.allShopExpressFee;
				}
			} else {
				expressMoney = storeInfo.shopExpressFee.allShopExpressFee;
			}
			this.distributionFee = expressMoney;
		},
		// 获取优惠券列表，将与优惠券匹配的商品筛选出来
		getcouponList() {
			let postdata = {
				businessId: this.businessId,
				status: 0
			};
			searchPlugsCouponsByUserId(postdata).then((res) => {
				if (res.code == 200) {
					this.couponList = res.body.list;
					let list = res.body.list;
					let list2 = list.filter((item) => item.plugsCoupons.goodsType == 2);
					
					// let goodIds = [];
					// list2.forEach((item, index) => {
					// 	let idsArr = item.plugsCoupons.goodsIds.split(',');
					// 	goodIds = goodIds.concat(idsArr)
					// })
					// let idsStr = goodIds.join();
					
					// let list3 = this.shopCartList.filter((item) => idsStr.includes(item.goodsId));
					// console.log(list3, 'list3')
					// let mony = 0;
					// list3.forEach((itm) => {
					// 	mony += itm.goodsSpecification[0].dealPrice * itm.goodsNum;
					// });
					// this.appointMoney = mony;
				}
			});
		},
		close() {
			this.paypalShow = false;
		},
		paypalOrderTap(e) {
			let self = this;
			if (self.logisticsType == 3) {
				if (!self.selfaddress.name) {
					uni.showModal({
						title: '订单提示',
						content: '请输入姓名',
						success(res) {}
					});
					uni.hideLoading();
					return;
				} else if (!self.selfaddress.mobile) {
					uni.showModal({
						title: '订单提示',
						content: '请输入联系电话',
						success(res) {}
					});
					uni.hideLoading();
					return;
				} else if (!/^1[3456789]\d{9}$/.test(self.selfaddress.mobile)) {
					uni.showModal({
						title: '手机格式错误',
						content: '请输入正确的手机号码',
						success(res) {}
					});
					uni.hideLoading();
					return;
				}
			} else if (self.logisticsType == 1) {
				if (!self.currentAddress.mobile) {
					uni.showModal({
						title: '订单提示',
						content: '还没有收货地址，请先选择或添加收货地址！',
						confirmText: '选择地址',
						success(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/user/addressList?type=select'
								});
							}
						}
					});
					uni.hideLoading();
					return;
				} else if (JSON.parse(self.goodsTotal) < JSON.parse(self.storeInfo.shopExpressFee.orderStartMoney)) {
					uni.showModal({
						title: '订单提示',
						content: '订单金额小于起送金额，起送金额为' + self.storeInfo.shopExpressFee.orderStartMoney + '元',
						showCancel: false
					});
					uni.hideLoading();
					return;
				} else if (self.num > JSON.parse(self.storeInfo.shopExpressFee.maxDeliveryDistance)) {
					uni.showModal({
						title: '订单提示',
						content: '下单距离大于配送距离，配送距离为' + self.storeInfo.shopExpressFee.maxDeliveryDistance + '米',
						showCancel: false
					});
					uni.hideLoading();
					return;
				}
			}
			uni.showLoading({
				title: '订单准备中',
				mask: true
			});
			let postData = {
				latitude: 0,
				logisticsType: this.logisticsType,
				longitude: 0,
				payMoney: 0,
				businessId: self.businessId,
				orderGoodsDTOS: self.goodsOrderList,
				receiverAddress: '',
				shopCartIds: self.cartListId,
				userCouponId: self.selectCoupon.id,
				orderRemark: self.ordermark,
				areaCode: 0,
				distributionFee: self.distributionFee,
				discount: this.firm_rate
			};
			if (this.logisticsType == 1 && self.currentAddress.areaCode) {
				postData.areaCode = self.currentAddress.areaCode;
				postData.latitude = self.currentAddress.latitude;
				postData.longitude = self.currentAddress.longitude;
			}
			
			console.log(this.final_goods_price, 'final_goods_price')
			
			if (self.logisticsType == 1) {
				postData.receiverAddress = JSON.stringify(self.currentAddress);
				postData.payMoney = Number(self.final_goods_price) + Number(self.distributionFee);
			} else if (self.logisticsType == 3) {
				postData.receiverAddress = JSON.stringify(self.selfaddress);
				postData.payMoney = JSON.parse(self.final_goods_price);
				let time = this.getNowTime();
				postData.expectPickTime = time;
				// postData.expectPickTime = self.pickupTime;
			}
			createOrder(postData).then((res) => {
				uni.hideLoading();
				if (res.code === 200) {
					self.orderInfo = res.body;
					let id = JSONBig.stringify(self.orderInfo.id);
					if (!self.goodsScoreStatus) {
						self.paypalShow = true;
					}
				} else {
					uni.showModal({
						title: '订单提示',
						content: res.msg,
						showCancel: false
					});
					return;
				}
			});
		},
		// 微信支付
		getPaypalOrder() {
			let self = this;
			let postData = {
				client: '小程序',
				openId: self.openId,
				orderId: self.orderInfo.id,
				orderNo: self.orderInfo.orderNo,
				payMoney: self.orderInfo.payMoney,
				payWay: 1,
				payType: 0,
				businessId: self.businessId
			};
			uni.showLoading({
				title: '支付准备中',
				mask: true
			});
			partnerAppletsWechatOrderPay(postData).then((res) => {
				if (res.code === 200) {
					self.payList = res.body;
					let data = res.body;

					uni.hideLoading();
					self.time = Date.now();
					wx.requestPayment({
						appId: self.payList.appid,
						nonceStr: self.payList.noncestr,
						package: self.payList.package,
						signType: 'RSA',
						timeStamp: self.payList.timestamp,
						paySign: self.payList.sign,
						success: function (res) {
							this.show = false;
							uni.showToast({
								title: '微信支付成功'
							});
							setTimeout(function () {
								uni.redirectTo({
									url: `/pages/order/paySuccess/paySuccess?id=${self.orderInfo.id}&money=${self.orderInfo.payMoney}`
								});
							}, 600);
						},
						fail: function (err) {
							console.log(err, '错误信息');
							uni.showModal({
								title: '支付失败',
								content: '订单支付失败，请重新进行支付。如对订单金额有疑问请联系客服人员',
								showCancel: false
							});
							return;
						}
					});
				} else {
					uni.hideLoading();
					uni.showModal({
						title: '支付失败',
						content: res.msg,
						showCancel: false
					});
				}
			});
		},
		// 余额支付
		balancePay() {
			let self = this;
			if (this.userInfo.balance < self.orderInfo.payMoney) {
				return uni.$showMsg('余额不足,请充值');
			}
			let postdata = {
				client: '小程序',
				extParm: '',
				openId: self.openId,
				orderId: self.orderInfo.id,
				orderNo: self.orderInfo.orderNo,
				payMoney: self.orderInfo.payMoney,
				payType: 0,
				payWay: 4
			};
			uni.showLoading({
				title: '支付准备中',
				mask: true
			});
			balanceOrderPay(postdata).then((res) => {
				if (res.code == 200) {
					uni.hideLoading();
					uni.showToast({
						title: '余额支付成功'
					});
					setTimeout(function () {
						let id = JSON.parse(JSON.stringify(self.orderInfo.id));
						uni.navigateTo({
							url: `/pages/order/paySuccess/paySuccess?id=${id}&&money=${self.orderInfo.payMoney}`
						});
					}, 600);
				} else {
					uni.hideLoading();
					uni.$showMsg('余额不足,请充值');
				}
			});
		},
		// 积分支付
		scorePay() {
			let self = this;
			if (this.userInfo.integral < self.orderInfo.payMoney) {
				return uni.$showMsg('积分不足');
			}

			let postdata = {
				"client": "小程序",
				"extParm": "",
				"openId": self.openId,
				"orderId": self.orderInfo.id,
				"orderNo": self.orderInfo.orderNo,
				"payMoney": self.orderInfo.payMoney,
				"payType": 0,
				"payWay": 3,
				"businessId": self.businessId
			}
			uni.showLoading({
				title: '支付准备中',
				mask: true
			});
			integralOrderPay(postdata).then(res => {
				if (res.code == 200) {
					uni.hideLoading();
					uni.showToast({
						title: '积分支付成功'
					});
					setTimeout(function() {
						uni.redirectTo({
							url: `/pages/order/paySuccess/paySuccess?id=${self.orderInfo.id}&&money=${self.orderInfo.payMoney}&&score=1`
						});
					}, 600);
				} else {
					uni.hideLoading();
					uni.showToast({
						title: res.msg
					});
				}
			})
		},
		getBindWechatPhoneTap(e) {
			let self = this;
			let wechatServerJSON = {
				code: e.detail.code
			};
			let data = {
				wechatServerJSON: JSON.stringify(wechatServerJSON)
			};
			getWeChartUserPhone(data).then((res) => {
				if (res.code === 200) {
					self.selfaddress.mobile = res.body.phone_info.phoneNumber;
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					// 将手机号存入用户信息
					if (this.userInfo.mobile != self.selfaddress.mobile) {
						let postdta = {
							mobile: self.selfaddress.mobile
						};
						updateUserInfo(postdta).then(() => {
							this.getUserInfo();
						})
					}
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			});
		},
		getPathTap(path) {
			uni.navigateTo({
				url: path
			});
		}
	}
};
</script>

<style lang="less">
.store_box {
	width: 100%;
	// padding-top: 20rpx;
	// margin-top: -60rpx;
	z-index: 100;
	.store {
		width: 100%;
		margin: 0 auto;
		margin-bottom: 20rpx;
		z-index: 999;
		background-color: #fff;
		// box-shadow: 0px 0px 16rpx 0px rgba(207, 207, 207, 0.5);
		// border: 3rpx solid #dadbdc;
		border-radius: 8rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		box-sizing: border-box;

		.left {
			// width: 130rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.title {
				font-weight: bold;
			}

			.address {
				margin: 6rpx 0;
				padding-right: 60rpx;
				box-sizing: border-box;
			}

			.time {
				font-size: 24rpx;
				color: #aaa;
			}

			image {
				width: 100rpx;
				height: 100rpx;
				border: 1px solid #f5f5f5;
				border-radius: 100%;
			}
		}

		.right {
			display: flex;
			align-items: center;
			.right-box {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 60rpx;
				height: 60rpx;
				border-radius: 100%;
				background-color: #e3f0fc;
			}
		}
	}
}
.content {
	padding-bottom: 120rpx;
	margin-bottom: env(safe-area-inset-bottom);
}



.showBox {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 40rpx;

	.pheader {
	}

	.paypalList {
		width: 94%;
		margin: 30rpx 0 200rpx 0;

		.paypal {
			width: 80%;
			margin: auto;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;

			.paypal-left {
				display: flex;
				align-items: center;

				.right {
					margin-left: 26rpx;
					
					.info{
						font-size: 28rpx;
						color: #6a6a6a;
					}
				}
			}
		}
	}
}

.firm_discount{
	display: flex;
	justify-content: space-between;
	padding: 20rpx 36rpx;
	box-sizing: border-box;
	font-size: 30rpx;
	font-weight: bold;
	
	.firm_discount_text{
		
	}
}

.menu_box {
	width: 100%;
	margin: 0 auto;
	background-color: #fff;
	border-radius: 20rpx;
	margin-bottom: 10rpx;

	.head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 100rpx;
		width: 90%;
		margin: 0 auto;

		.left {
			color: #1c1c1c;
			font-size: 30rpx;
			font-weight: bold;
			line-height: 30rpx;
			display: flex;
			align-items: center;
		}

		.right {
			color: #999;
			display: flex;
			align-items: center;
			font-size: 26rpx;
			line-height: 26rpx;
		}
	}

	.delivery_box {
		width: 90%;
		margin: 0 auto;
		padding: 10rpx 0 50rpx;
		display: flex;

		/deep/.u-radio {
			flex: 1;
		}
	}

	.phone_box {
		width: 90%;
		margin: 0 auto;
		margin-bottom: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		border: 1px solid #eee;
		border-radius: 10rpx;
		overflow: hidden;

		.input {
			flex: 1;
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			input {
				width: 100%;
				color: #1c1c1c;
				font-size: 30rpx;
				height: 100%;
				padding-left: 20rpx;
			}
		}

		.btn {
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 0 20rpx;
			box-sizing: border-box;
			font-size: 28rpx;
			margin-left: 20rpx;
			position: relative;
			background-color: #eaeaea;
			color: #6a6a6a;

			.button {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				opacity: 0;
				padding: 0;
			}
			.button::after{
				
			}
		}
	}

	

	.goods_box {
		padding-bottom: 2rpx;

		.goods {
			width: 90%;
			margin: 0 auto;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 40rpx;

			.left {
				width: 200rpx;

				image {
					width: 180rpx;
					height: 180rpx;
					border-radius: 20rpx;
				}
			}

			.right {
				flex: 1;
				min-width: 0;
				height: 170rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.goodsSpec {
					font-size: 24rpx;
					color: #999;
					display: -webkit-box; //将对象作为弹性伸缩盒子模型显示
					-webkit-box-orient: vertical; //设置或检索伸缩盒对象的子元素的排列方式
					-webkit-line-clamp: 3; //一个块元素显示的文本的行数
					overflow: hidden; //溢出隐藏
				}

				.title {
					color: #1c1c1c;
					font-size: 30rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.text {
					color: #999;
					font-size: 28rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.price {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.num {
						color: #f14b5b;
						font-size: 32rpx;
						font-weight: bold;
						display: flex;
						align-items: center;

						span {
							font-size: 28rpx;
							padding-left: 2rpx;
						}
					}

					.buy {
						color: #f54319;
						// padding: 0 10rpx;
						border-radius: 10rpx;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}
		}
	}

	.coupons_box {
		padding: 0 0 20rpx;

		.label {
			width: 90%;
			height: 120rpx;
			margin: 0 auto;
			border: 1px solid #f5f5f5;
			border-radius: 20rpx;
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;

			.price {
				width: 150rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #f14b5b;
				font-size: 38rpx;
				font-weight: bold;
				line-height: 38rpx;

				span {
					font-size: 24rpx;
					padding-left: 2rpx;
					margin-bottom: -4rpx;
				}
			}

			.info {
				flex: 1;
				min-width: 0;
				display: flex;
				flex-direction: column;
				justify-content: center;

				.title {
					color: #1c1c1c;
					font-size: 30rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.text {
					font-size: 26rpx;
					color: #999;
					padding-top: 4rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}

			.button {
				width: 110rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}

	.order_info_box {
		margin-bottom: 160rpx;
		
		.order_head {
			width: 90%;
			margin: 0 auto;

			.label {
				display: flex;
				align-items: center;
				padding-bottom: 30rpx;
				justify-content: space-between;
				font-size: 28rpx;
				color: #999;
			}
		}

		.order_foot {
			border-top: 1px solid #f5f5f5;

			.label {
				display: flex;
				align-items: center;
				width: 90%;
				margin: 0 auto;
				justify-content: space-between;
				height: 90rpx;
				font-weight: bold;
				font-size: 30rpx;
			}
		}
	}
}

.pickUp{
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	font-size: 28rpx;
	padding: 0 5% 20rpx 5%;
	margin-bottom: 10rpx;
	
	.title{
		padding-bottom: 20rpx;
	}
}

.pay_type_box {
	width: 92%;
	margin: 0 auto;
	background-color: #fff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-radius: 20rpx;
	height: 100rpx;

	.icons {
		width: 100rpx;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.title {
		flex: 1;
		color: #1c1c1c;
		font-size: 28rpx;
	}

	.right {
		width: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}
}

.footer {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	z-index: 100;
	background-color: #fff;
	padding-bottom: env(safe-area-inset-bottom);
	border-top-left-radius: 20rpx;
	border-top-right-radius: 20rpx;

	.label {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 120rpx;
		width: 100%;

		.button {
			width: 92%;
			margin: 0 auto;
			height: 80rpx;
			border-radius: 100rpx;
			color: #fff;
			font-size: 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #01cb88;

			/deep/.u-count-down__text {
				color: #fff;
				line-height: 30rpx;
				padding: 0 4rpx;
			}
		}
	}
}
</style>
